// Copyright 2000-2020 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.

package com.kyexpress.vms.component;

import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.ui.TextBrowseFolderListener;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.ui.components.JBComboBoxLabel;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBTextField;
import com.intellij.util.ui.FormBuilder;
import com.kyexpress.vms.enitity.DataCenter;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

/**
 * Supports creating and managing a {@link JPanel} for the Settings Dialog.
 */
public class AppSettingsComponent {
  
  public static final String YOU_DAO="有道";
  public static final String BAI_DU="百度";

  private  JPanel myMainPanel;
  private  JBTextField dictUrl = new JBTextField();
  private   JComboBox dict_select = new JComboBox();
  private  JBTextField moduleName = new JBTextField();
  private  JBTextField packageName = new JBTextField();
  private  JBTextField author = new JBTextField();
  private  JBTextField app_id = new JBTextField();
  private  JBTextField app_secret = new JBTextField();
  private FileChooserDescriptor singleFolderDescriptor;


  public AppSettingsComponent() {
   /* singleFolderDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    singleFolderDescriptor.setTitle("包名");
    singleFolderDescriptor.withFileFilter(item->item.isDirectory());
    
    packageName.addBrowseFolderListener(new TextBrowseFolderListener(singleFolderDescriptor));*/
    dict_select.addItem(YOU_DAO);
    dict_select.addItem(BAI_DU);
    myMainPanel = FormBuilder.createFormBuilder()
            .addLabeledComponent(new JBLabel("选择词典: "), dict_select, 1, false)
            .addLabeledComponent(new JBLabel("输入文件中心网关地址: "), dictUrl, 1, false)
            .addLabeledComponent(new JBLabel("api模块名: "), moduleName, 1, false)
            .addLabeledComponent(new JBLabel("输入枚举所在包的包名: "), packageName, 1, false)
            .addLabeledComponent(new JBLabel("作者: "), author, 1, false)
            .addLabeledComponent(new JBLabel("百度翻译app_id: "), app_id, 1, false)
            .addLabeledComponent(new JBLabel("百度翻译app_secret: "), app_secret, 1, false)
            .addComponentFillVertically(new JPanel(), 0)
            .getPanel();
  }

  public JPanel getPanel() {
    return myMainPanel;
  }

  public JComponent getPreferredFocusedComponent() {
    return dictUrl;
  }
  
  
  @NotNull
  public String getDictUrl() {
    return dictUrl.getText();
  }
  
  public String getPackageName() {
    return packageName.getText();
  }
  
  
  public String getAuthor() {
    return author.getText();
  }
  
  public String getApp_id() {
    return app_id.getText();
  }
  
  public String getApp_secret() {
    return app_secret.getText();
  }
  
  public void setDictUrl(String dictUrl) {
    this.dictUrl.setText(dictUrl);
  }
  
  public void setPackageName(String packageName) {
    this.packageName.setText(packageName);
  }
  
  
  public void setAuthor(String author) {
    this.author.setText(author);
  }
  
  public void setApp_id(String app_id) {
    this.app_id.setText(app_id);
  }
  
  public void setApp_secret(String app_secret) {
    this.app_secret.setText(app_secret);
  }
  
  public String getModuleName() {
    return moduleName.getText();
  }
  
  public void setModuleName(String moduleName) {
    this.moduleName.setText(moduleName);
  }
  
  public String getDict_select() {
    return (String) dict_select.getSelectedItem();
  }
  
  public void setDict_select(String dict_select) {
    this.dict_select.setSelectedItem(dict_select);
  }
}
